/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.asset.bean;

import com.yunhoo.base.model.Department;
import com.yunhoo.base.model.Person;
import com.yunhoo.sys.db.util.IbatisTemplate;
import com.yunhoo.sys.util.common.CommonParam;
import com.yunhoo.sys.util.common.LoginParam;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.model.SelectItem;

/**
 *
 * @author Administrator
 */
public class DeptAndPsnRelation {

    public static Map intiDepartmentInfo() {
        List<SelectItem> deptSelectList = new ArrayList();
        Map<String, String> deptMap = new HashMap<String, String>();
        List<Department> deptlist = CommonParam.departmentList();
        for (Department d : deptlist) {
            deptSelectList.add(new SelectItem(d.getCode(), d.getName()));
            deptMap.put(d.getCode().trim(), d.getName().trim());
        }
        Map map = new HashMap();
        map.put("deptList", deptSelectList);
        map.put("deptMap", deptMap);
        return map;
    }

    //返还所选部门人员信息
    public static Map deptChange(String deptCode) {
        List<SelectItem> person = new ArrayList();
        Map<String, String> psns = new HashMap<String, String>();
        Person param = new Person();
        param.setOrgCode(LoginParam.getOrg().getCode());
        param.setIyear(LoginParam.getIyear());
        param.setDeptCode(deptCode);
        List<Person> personlist = IbatisTemplate.queryForList("person.queryListByDept", param);
        if (personlist != null && personlist.size() > 0) {
            for (Person p : personlist) {
                person.add(new SelectItem(p.getCpsn_number(), p.getCpsn_name()));
                psns.put(p.getCpsn_number().trim(), p.getCpsn_name().trim());
            }
        }
        Map map = new HashMap();
        map.put("psnList", person);
        map.put("psnMap", psns);
        return map;
    }
}
